package com.example.crm.controller;

import com.example.crm.entity.Business;
import com.example.crm.service.BusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/businesses")
public class BusinessController {
    @Autowired
    private BusinessService businessService;

    @GetMapping
    public List<Business> getAllBusinesses() {
        return businessService.findAll();
    }

    @GetMapping("/{id}")
    public Business getBusinessById(@PathVariable Integer id) {
        return businessService.getBusinessById(id);
    }

    @PostMapping
    public Business createBusiness(@RequestBody Business business) {
        return businessService.save(business);
    }

    @PutMapping("/{id}")
    public Business updateBusiness(@PathVariable Integer id, @RequestBody Business business) {
        business.setBusinessid(id);
        return businessService.save(business);
    }

    @DeleteMapping("/{id}")
    public void deleteBusiness(@PathVariable Integer id) {
        businessService.deleteBusiness(id);
    }
}
